import { defineStore } from "pinia";
import { withdrawal, withdrawalRecord, walletRecord } from "@/apis/wallet.js";

export const useWalletStore = defineStore("wallet", {
  state: () => {
    return {};
  },

  getters: {},

  actions: {
    // 提现
    async fetchWithdrawal(data) {
      const res = await withdrawal(data);
      if (res.result.success) {
        uni.$u.toast("申请提现成功");
      }
      return Promise.resolve(res.result.success);
    },
    // 提现记录
    async fetchWithdrawalRecord(params) {
      const res = await withdrawalRecord(params);
      if (res.result.success) {
        return res.result.data;
      }
      return [];
    },
    // 佣金记录
    async fetchWalletRecord(params) {
      const res = await walletRecord(params);
      if (res.result.success) {
        return res.result.data;
      }
      return [];
    },
  },
});
